layui.config({
    version: '1510164124181'
}).use(['form', 'laydate', 'laypage', 'layer', 'element'], function() {
    form = layui.form;
    layer = layui.layer;
    $ = layui.jquery;
    laydate = layui.laydate; //日期
    laypage = layui.laypage; //分页
    element = layui.element; //元素操作
    TypelistByTypeId(3);
    inituserdata();
});

function SearchInfo() {
    pageNo = 1;
    inituserdata();
}

function onloadInfo() {
    inituserdata();
}

function inituserdata() {
    let typeid = $(".typelist option:selected").val();
    $.ajax({
        url: httpurl + "/FindCouponListPc",
        cache: false,
        headers: {
            "Access-Control-Allow-Origin": "*",
            "Access-Control-Allow-Methods": "*",
            "Access-Control-Allow-Headers": "Authorization",
            "Authorization": GetTokenInfo()
        },
        contentType: 'application/json',
        data: {
            "page": pageNo,
            "pagesize": pageRecords,
            "typeid": typeid
        },
        success: function(data) {
            let dataHtml = "";
            if (data.rtnCode == 200) {
                let dataList = data.data.list;
                totalRecords = data.data.total;
                for (let i = 0; i < dataList.length; i++) {
                    dataHtml += '<tr>' +
                        '<td><input type="checkbox"  name="box" class="aceChild" data-id="' + dataList[i].id + '"/></td>' +
                        '<td align="center">' + (isNotNull(dataList[i].typeList) ? dataList[i].typeList.name : "") + '</td>' +
                        '<td align="center">' + dataList[i].name + '</td>' +
                        '<td align="center">' + dataList[i].val + '</td>' +
                        '<td align="center">' + dataList[i].num + '</td>' +
                        '<td align="center">' + (dataList[i].isdispaly == 1 ? "不显示" : "显示") + '</td>' +
                        '<td align="center">' + (dataList[i].starttime + "-" + dataList[i].endtime) + '</td>' +
                        '<td align="center">' +
                        '<a href="AddCoupon.html?CouponId=' + dataList[i].id + '" >编辑</a>&nbsp;&nbsp;&nbsp;' +
                        '<a href="#" data-id="' + dataList[i].id + '"  data-info="deleteCouponId"  onclick="DeleteInfo(this)">删除</a>' +
                        '</td>' +
                        +'</tr>';
                }
            } else {
                totalRecords = 0;
                dataHtml += '<tr>' +
                    '<td colspan="12" style="text-align:center;">暂无数据</td>' +
                    '</tr>';
            }
            $("#tableInfo tbody").html(dataHtml);
            pageLayPage("inituserdata");
        }

    });

}